package com.um.jdy.app.shop.controller;

import com.um.jdy.app.shop.entity.dto.GoodsPageDTO;
import com.um.jdy.app.shop.entity.dto.RecommendGoodsListDTO;
import com.um.jdy.app.shop.entity.vo.GoodsDetailVO;
import com.um.jdy.app.shop.entity.vo.GoodsItemVO;
import com.um.jdy.app.shop.entity.vo.GoodsRecomendItemVO;
import com.um.jdy.app.shop.manager.GoodsManager;
import com.um.jdy.common.shop.entity.vo.GoodsOptionVO;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 商品
 * @author renjunwei
 * @date 2020/9/18 18:10
 */
@Api(tags = "商品")
@RestController
@RequestMapping("/api/v1/goods/")
@Validated
public class GoodsContoller {

    @Autowired
    GoodsManager goodsManager;

    /**
     * 分页查询商品
     * @param dto
     * @return
     */
    @ApiOperation("分页查询商品")
    @PostMapping("get_page")
    public Response<Page<GoodsItemVO>> getPage(@Valid @RequestBody GoodsPageDTO dto){
        return Response.success(goodsManager.getPage(dto));
    }

    /**
     * 查询商品详情
     * @param id
     * @return
     */
    @ApiOperation("查询商品详情")
    @GetMapping("{id}")
    public Response<GoodsDetailVO> get(@PathVariable @ApiParam("商品id") String id){
        return Response.success(goodsManager.get(id));
    }

    /**
     * 查询商品规格
     * @param id
     * @return
     */
    @ApiOperation("查询商品规格")
    @GetMapping("options/{id}")
    public Response<List<GoodsOptionVO>> getOptionList(@PathVariable @ApiParam("商品id") String id){
        return Response.success(goodsManager.getOptionList(id));
    }

    /**
     * 查询推荐商品
     * @param dto
     * @return
     */
    @ApiOperation("查询推荐商品")
    @GetMapping("recommend")
    public Response<List<GoodsRecomendItemVO>> getRecommendGoods(@Valid @RequestBody RecommendGoodsListDTO dto){
        return Response.success(goodsManager.getRecommendGoods(dto.getType(), dto.getLimit()));
    }
}
